package inabit.agent;
/**@author Rafael Rocha*/
public abstract class Sensor{

	private String id;
	private String state;
	private String lastState;
	
	public Sensor(String id) {
		this.id = id;
		this.state = null;
		this.lastState = null;
	}

	public String getID() {
		return this.id;
	}

	/**updates the last state to the current state and updates the sensor current state
	 *  by calling the method <i>getState</i> and*/
	public void updateState() {
		lastState = state;
		state = getState();
	}
	/**Returns the last state recorded by the sensor when the method
	 * <i>updateState</i> was called*/
	public String getCurrentState() {
		return state;
	}
	/**Returns the state before the current state recorded by the sensor*/
	public String getLastState() {
		return this.lastState;
	}
	/**Returns true if the sensor state has changed in the most recent call of <i>updateState</i> method*/
	public boolean hasStateChanged() {
		return lastState != state;
	}
	/**Returns the reading of this sensor from the
	 * environment*/
	protected abstract String getState();
}
